﻿function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    localStorage.setItem(c_name, value);
    localStorage.setItem(c_name + "time", exdate.adddays(expiredays).toGMTString());
}
function getCookie(c_name) {
    var val = localStorage.getItem(c_name);
    var time = localStorage.getItem(c_name + "time");
    if (val != null) {
        var now = new Date();
        var exp = new Date(time);
        if (now < exp)
            return val;
        else
            return "";
    }
    return "";
}
//删除cookies
function delCookie(name) {
    localStorage.removeItem(name);
    localStorage.removeItem(name + "time");
}

function setCookie1(c_name, value, expiredays) {
    var exdate = new Date()
    //exdate.setDate(exdate.getDate() + expiredays)
    document.cookie = c_name + "=" + escape(value) +
    ((expiredays == null) ? "" : ";expires=" + exdate.adddays(expiredays).toGMTString())
}

function getCookie1(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=")
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1
            c_end = document.cookie.indexOf(";", c_start)
            if (c_end == -1) c_end = document.cookie.length
            return unescape(document.cookie.substring(c_start, c_end))
        }
    }
    return ""
}

//删除cookies
function delCookie1(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

function checkPass() {
    var pwd = getCookie("gzapwd");
    if (pwd === "") {
        location.href = "login.html";
    }
}

checkPass();

function logout() {
    delCookie("gzapwd");
    location.href = "login.html";
}